USE [ManagerEmployees]
GO


-- 8/3
CREATE VIEW View_Districts
AS
SELECT		Districts.*, Provinces.NameOfProvince
FROM        Districts INNER JOIN Provinces ON Districts.ProvID = Provinces.ProvID
GO


CREATE VIEW View_Communes
AS
SELECT			Communes.*, Districts.NameOfDist AS Expr1, Provinces.NameOfProvince, Districts.DistID AS Expr2, Provinces.ProvID
FROM			Communes	INNER JOIN Districts ON Communes.DistID = Districts.DistID 
							INNER JOIN Provinces ON Districts.ProvID = Provinces.ProvID
GO



CREATE VIEW View_Ogranizations
AS
SELECT				Organizations.*, Communes.ComID AS Expr1, Communes.NameOfComm, Districts.DistID, Districts.NameOfDist, Provinces.ProvID, Provinces.NameOfProvince
FROM				Communes	INNER JOIN Districts ON Communes.DistID = Districts.DistID 
								INNER JOIN Organizations ON Communes.ComID = Organizations.ComID 
								INNER JOIN Provinces ON Districts.ProvID = Provinces.ProvID
GO


CREATE VIEW View_Departments
AS
SELECT	Communes.ComID AS Expr1, Communes.NameOfComm, Districts.DistID, Districts.NameOfDist, Provinces.ProvID, 
		Provinces.NameOfProvince, Departments.*, Organizations.OrgID AS Expr2, Organizations.NameOfOrgan
FROM	Communes	INNER JOIN Districts ON Communes.DistID = Districts.DistID 
					INNER JOIN Organizations ON Communes.ComID = Organizations.ComID 
					INNER JOIN Provinces ON Districts.ProvID = Provinces.ProvID 
					INNER JOIN Departments ON Organizations.OrgID = Departments.OrgID
GO